package com.asm.DBloader;

import java.util.ArrayList;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

public class ASM_FinvHedDS {
	private SQLiteDatabase dB;
	private ASM_DB dbHelper;
	Context context;
	
	
	public ASM_FinvHedDS(Context context) {
		this.context = context;
		dbHelper  = new ASM_DB(context);
		
	}
	
	public void open() throws SQLException
	{
		dB = dbHelper.getWritableDatabase();
	}
	public int Create(ASM_FinvHed det) {
		
		int count =0;
		
		if(dB == null){
			open();
		}else if(!dB.isOpen()){
			open();
		}
		
		 
	
		ContentValues values = new ContentValues();
		values.put(ASM_DB.asmInvHed_RefNo, det.getAsmInvHed_RefNo());
		values.put(ASM_DB.asmInvHed_RefNo1, det.getAsmInvHed_RefNo1() );
		values.put(ASM_DB.asmInvHed_TxnDate,det.getAsmInvHed_TxnDate());
		
		
		values.put(ASM_DB.asmInvHed_DealCode,det.getAsmInvHed_DealCode());
		values.put(ASM_DB.asmInvHed_RepCode,det.getAsmInvHed_RepCode());
		
		values.put(ASM_DB.asmInvHed_AreaCode, det.getAsmInvHed_AreaCode());
		values.put(ASM_DB.asmInvHed_DebCode, det.getAsmInvHed_DebCode());
		values.put(ASM_DB.asmInvHed_TotalAmt, det.getAsmInvHed_TotalAmt());
		values.put(ASM_DB.asmInvHed_AddDate, det.getAsmInvHed_AddDate());
		
		

		
		count = (int) dB.insert(ASM_DB.ASM_FINVHED, null, values);

		dB.close();
		return count;
		
	}
	
	public ArrayList<String> getInvoiceorderReport(String startdate,String enddate,String Repcode) 
	{
		if (dB == null) 
		{
			open();
		} else if (!dB.isOpen()) 
		{
			open();
		}
		ArrayList<String> Details = new ArrayList<String>();
		String selectQuery = "select a.TxnDate,a.RefNo,c.DebName,a.TotalAmt,b.TxnDate,b.TotalAmt,d.TxnDate,''  from FOrdHed as a inner join FinvHed as b on a.RefNo = b.RefNo1 inner join fDebtor as c on c.DebCode = a.DebCode inner join fInvrhed as d on b.RefNo = d.RefNo1"; //where a.RepCode = '"+Repcode+"' ";//and strftime('%Y-%m-%d',a.TxnDate) BETWEEN '"+startdate+"' and '"+enddate+"'";
		
		Cursor cursor = null;
		cursor = dB.rawQuery(selectQuery, null);
		
		System.out.println(cursor.getCount());
		while(cursor.moveToNext())
		{
		
			String LIst = cursor.getString(0)+"-"
			+cursor.getString(1)+"-"
					+cursor.getString(2)+"-"
			+cursor.getString(3)+"-"
					+cursor.getString(4)+"-"
			+cursor.getString(5)+"-"
					+cursor.getString(6)+"-";
	
			Details.add(LIst);
		
		}
		
	
		return Details;
	}
}
